/*
 * Copyright (C) 2012 Christopher Swartz, David Elrom

 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *   SOFTWARE.
 */

#include <stdint.h>

#include "radiotap.h"
#include "RadiotapParser.h"

RadiotapParser::RadiotapParser(const unsigned char* _data, size_t _size) :
	m_data(_data),
	m_size(_size)
{
}

RadiotapParser::~RadiotapParser() {
	// TODO Auto-generated destructor stub
}

bool RadiotapParser::tsftValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_TSFT));
}

bool RadiotapParser::flagsValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_FLAGS));
}

bool RadiotapParser::rateValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_RATE));
}

bool RadiotapParser::channelValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_CHANNEL));
}

bool RadiotapParser::fhssValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_FHSS));
}

bool RadiotapParser::antennaSignalValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
}

bool RadiotapParser::antennaNoiseValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE));
}

bool RadiotapParser::txAttenuationValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_TX_ATTENUATION));
}

bool RadiotapParser::dbTxAttenuationVlid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_DB_TX_ATTENUATION));
}

bool RadiotapParser::dbTxPowerValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_DBM_TX_POWER));
}

bool RadiotapParser::antennaValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_ANTENNA));
}

bool RadiotapParser::dbAntennaSignalValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL));
}

bool RadiotapParser::dbAntennaNoiseValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_DB_ANTNOISE));
}

bool RadiotapParser::rxFlagsValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_RX_FLAGS));
}

bool RadiotapParser::mcsValid() const {
	return isValid() && (reinterpret_cast<const ieee80211_radiotap_header*>(m_data)->it_present & (1 << IEEE80211_RADIOTAP_MCS));
}

bool RadiotapParser::isValid() const {
	if (!m_data)
		return false;

	// TODO: check other conditions

	return true;
}


